package com.bocai.open.mapper;

import com.bocai.open.model.WinRanker;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author create by VIC.Huang
 * @date 2018/3/10
 */
@Mapper
@Component
public interface OpenMapper {
    @Select("<script>" +
            " select tu.wx_head_img headImg, tu.nick_name nickName, t.winCount from ( " +
            "   select user_id, count(1) winCount from t_spend_record " +
            "   where type = 'WIN' " +
            "   <if test='type == 1'> and date(create_time) = curdate() </if>" +
            "   <if test='type == 2'> and yearweek(date_format(create_time,'%Y-%m-%d')) = yearweek(now()) </if>" +
            "   <if test='type == 3'> and date_format(create_time,'%Y-%m')=date_format(now(),'%Y-%m') </if>" +
            "   group by user_id limit 0,10 " +
            " ) t join t_user tu on t.user_id = tu.id " +
            " order by t.winCount desc " +
            "</script>")
    List<WinRanker> getWinRanker(@Param("type") Integer type);
}
